﻿@page "/Wms/SaleReturnInWarehouseDetail/Edit"
@using nERP.ViewModel.Wms.SaleReturnInWarehouseDetailVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
            <BootstrapInput @bind-Value="@Model.Entity.Seq" />
            <Select @bind-Value="@Model.Entity.SaleReturnInWarehouseId" Items="AllSaleReturnInWarehouses" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="ga3829d7677f245b2b59745d5fadb07ce" />
            <BootstrapInput @bind-Value="@Model.Entity.SaleReturnInWarehouseDetailCode" />
            <Select @bind-Value="@Model.Entity.SaleReturnId" Items="AllSaleReturns" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g0357ad598604449e83c9499393632076" />
            <Select @bind-Value="@Model.Entity.SaleReturnDetailId" Items="AllSaleReturnDetails" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="gc8682cfd39464fd88b1cf5db19daf5ad" />
            <Select @bind-Value="@Model.Entity.WarehouseId" Items="AllWarehouses" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g3cb829dfddf142dc8749b61b790b01f8" />
            <Select @bind-Value="@Model.Entity.GoodsId" Items="AllGoodss" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g50f9fe13f15042c283cff082bef85c0c" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsName" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsSpec" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsUnit" />
            <BootstrapInput @bind-Value="@Model.Entity.ReturnNumber" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.Remark" />
        </Row>

        <div class="modal-footer table-modal-footer">
            <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]" />
            <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private SaleReturnInWarehouseDetailVM Model = new SaleReturnInWarehouseDetailVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/Wms/SaleReturnInWarehouseDetail/Edit", (s) => "Sys.OprationSuccess", method: HttpMethodEnum.PUT);
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllSaleReturnInWarehouses = new List<SelectedItem>();
    private List<SelectedItem> AllSaleReturns = new List<SelectedItem>();
    private List<SelectedItem> AllSaleReturnDetails = new List<SelectedItem>();
    private List<SelectedItem> AllWarehouses = new List<SelectedItem>();
    private List<SelectedItem> AllGoodss = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllSaleReturnInWarehouses = await WtmBlazor.Api.CallItemsApi("/api/Wms/SaleReturnInWarehouseDetail/GetSaleReturnInWarehouses");
        AllSaleReturnInWarehouses.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSaleReturns = await WtmBlazor.Api.CallItemsApi("/api/Wms/SaleReturnInWarehouseDetail/GetSaleReturns");
        AllSaleReturns.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSaleReturnDetails = await WtmBlazor.Api.CallItemsApi("/api/Wms/SaleReturnInWarehouseDetail/GetSaleReturnDetails");
        AllSaleReturnDetails.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllWarehouses = await WtmBlazor.Api.CallItemsApi("/api/Wms/SaleReturnInWarehouseDetail/GetWarehouses");
        AllWarehouses.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllGoodss = await WtmBlazor.Api.CallItemsApi("/api/Wms/SaleReturnInWarehouseDetail/GetGoodss");
        AllGoodss.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<SaleReturnInWarehouseDetailVM>($"/api/Wms/SaleReturnInWarehouseDetail/{id}");
            Model = rv.Data;
        }

        await base.OnInitializedAsync();
    }
}
